#ifndef SMA_H_INCLUDED
#define SMA_H_INCLUDED

#include <stdio.h>
#include <assert.h>

class sma {
public:
	sma(unsigned int period) : period(period), window(new double[period]), head(NULL), tail(NULL), total(0)
    {
        assert(period >= 1);
    }

	~sma()
	{
        delete[] window;
	}

	void add(double val);
	double avg() const;

private:
	unsigned int period;
	double * window;
	double * head;
	double * tail;
	double total;

	void inc(double * & p);
	ptrdiff_t size() const;
};

#endif // SMA_H_INCLUDED
